package com.maigao.entity.jpa;

import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;

@Data
@Entity
@Table(name = "tb_take_off_record")
@DynamicInsert
@DynamicUpdate
public class QueryTakeOffRecord implements Serializable {

    public enum Status {
        REVOKED(-1), CREATED(0), AUDIT_PASS(1), REFUSED(-1);

        Status(int value) {
            this.value = value;
        }

        private int value;

        public int getValue() {
            return value;
        }

        public static Status getByValue(int value) {
            Optional<Status> optional = Arrays.stream(values()).filter(p -> Objects.equals(p.getValue(), value)).findFirst();
            if (optional.isPresent()) {
                return optional.get();
            }
            return null;
        }
    }

    public enum NoticeStatus {
        INIT(0), NEED_NOTICE(1), HAS_NOTICED(2);

        NoticeStatus(int value) {
            this.value = value;
        }

        private int value;

        public int getValue() {
            return value;
        }

        public static NoticeStatus getByValue(int value) {
            Optional<NoticeStatus> optional = Arrays.stream(values()).filter(p -> Objects.equals(p.getValue(), value)).findFirst();
            if (optional.isPresent()) {
                return optional.get();
            }
            return null;
        }
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Column(name = "student_id")
    private Integer studentId;

    @Column(name = "student_name")
    private String studentName;

    @ManyToOne(cascade = CascadeType.PERSIST)
    @JoinColumn(name = "class_record_id")
    private ClassRecord classRecord;

    @Column(name = "status")
    private Integer status;

    @Column(name = "note")
    private String note;

    @Column(name = "approve_user_uid")
    private String approveUserUid;

    @Column(name = "approve_user_name")
    private String approveUserName;

    @Column(name = "create_time")
    private LocalDateTime createTime;

    @Column(name = "last_update_time")
    private LocalDateTime lastUpdateTime;

    @Column(name = "notice_status")
    private Integer noticeStatus;

}
